package com.ls.blog.controller;

import com.ls.blog.annotation.LogAnnotation;
import com.ls.blog.api.ArticleService;
import com.ls.blog.entity.Tag;
import com.ls.blog.result.JsonResult;
import com.ls.blog.api.TagsService;
import com.ls.blog.utils.ResultTool;
import com.ls.blog.vo.TagVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-05 14:14
 **/
@Api(tags = {"标签模块"})
@RestController
public class TagController {

    @Autowired
    private TagsService tagsService;

    @Autowired
    private ArticleService articleService;

    /**
     * 得到所有标签
     * @return
     */
    @ApiOperation("标签列表")
    @GetMapping("/tags")
    public JsonResult<Map<String,Object>> tags(){
        return ResultTool.success(tagsService.tags());
    }

    @ApiOperation("最热文章")
    @GetMapping("/hot")
    public JsonResult Hots(){
        int limit = 6;
        List<Tag> tags = tagsService.Hots(limit);
        return ResultTool.success(tags);
    }

    @ApiOperation("标签文章列表")
    @LogAnnotation(module = "标签",operation = "标签文章列表")
    @GetMapping("/tags/{id}")
    public JsonResult<Map<String,Object>> tagArticleList(@PathVariable("id") Long id, Long current){
        Map<String, Object> map = articleService.tagArticles(id, current);
        return ResultTool.success(map);
    }


//    @ApiOperation("标签细节列表")
//    @GetMapping("detail")
//    public JsonResult<List<TagVo>> TagDetail(){
//        return ResultTool.success(tagsService.TagDetail());
//    }

//    @ApiOperation("标签细节")
//    @GetMapping("detail/{id}")
//    public JsonResult<TagVo> findTagDetail(@PathVariable("id") Long id){
//        return ResultTool.success(tagsService.findTagsById(id));
//    }

}
